package com.foucus.myfouces.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.foucus.myfouces.MVP.Model.BannerResp;
import com.foucus.myfouces.Resource.Util.GliderUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yf-06 on 2017/7/13.
 */

public class BannerPageAdapter extends PagerAdapter {
    private Context context;
    private List<BannerResp.ResultBean.DataBean> adBannerList;

    public BannerPageAdapter(Context context, List<BannerResp.ResultBean.DataBean> bannerList) {
        if (adBannerList == null) {
            adBannerList = new ArrayList<BannerResp.ResultBean.DataBean>();
        }
        this.context = context;
        this.adBannerList = bannerList;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        ImageView imageView = new ImageView(context.getApplicationContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        String url = adBannerList.get(position).getThumb();
        GliderUtil.bannerGlider(context,url,imageView);

        container.addView(imageView);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


            }
        });
        return imageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        return adBannerList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
